package xing.example.config.converter;

import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.context.support.ConversionServiceFactoryBean;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.stereotype.Component;
import xing.example.converter.StringToA;
import xing.example.converter.StringToAGenericConverter;
import xing.example.converter.factory.StringToAConverterFactory;
import xing.example.bean.A;

import java.util.HashSet;
import java.util.Set;

/**
 * @author xing
 * @date 2023/2/15 20:55:17
 */
@Component("conversionService")
public class MyConversionService extends ApplicationConversionService implements ConverterRegistry {

    {
        // 使用 Converter 实现类
        // addConverter(new StringToA());

        // 使用 GenericConverter 实现类
        // 前面两参数可加 可不加
        // addConverter(String.class, A.class, new StringToAGenericConverter());

        // 使用 COnverTerFactory 实现类
        addConverterFactory(new StringToAConverterFactory());
    }

}
